{% extends "base.html" %}

{% block content %}
<div class="container mt-4">
    <div class="row justify-content-center">
        <div class="col-md-8">
            <div class="card">
                <div class="card-header">
                    <h4 class="card-title mb-0">编辑订单</h4>
                </div>
                <div class="card-body">
                    <form method="POST">
                        <div class="mb-3">
                            <label class="form-label">订单号</label>
                            <input type="text" class="form-control" value="{{ order.order_number }}" readonly>
                        </div>
                        <div class="mb-3">
                            <label class="form-label">客户名称</label>
                            <input type="text" class="form-control" name="customer_name" value="{{ order.customer_name }}" required>
                        </div>
                        <div class="mb-3">
                            <label class="form-label">联系电话</label>
                            <input type="text" class="form-control" name="customer_phone" value="{{ order.customer_phone }}" required>
                        </div>
                        <div class="mb-3">
                            <label class="form-label">地址</label>
                            <input type="text" class="form-control" name="customer_address" value="{{ order.customer_address }}" required>
                        </div>
                        <div class="mb-3">
                            <label class="form-label">订单类型</label>
                            <select class="form-select" name="order_type" required>
                                <option value="sample" {% if order.order_type == 'sample' %}selected{% endif %}>样本采集</option>
                                <option value="dna" {% if order.order_type == 'dna' %}selected{% endif %}>DNA检测</option>
                            </select>
                        </div>
                        <div class="mb-3">
                            <label class="form-label">状态</label>
                            <select class="form-select" name="status" required>
                                <option value="pending" {% if order.status == 'pending' %}selected{% endif %}>待处理</option>
                                <option value="processing" {% if order.status == 'processing' %}selected{% endif %}>处理中</option>
                                <option value="completed" {% if order.status == 'completed' %}selected{% endif %}>已完成</option>
                                <option value="cancelled" {% if order.status == 'cancelled' %}selected{% endif %}>已取消</option>
                            </select>
                        </div>
                        <div class="mb-3">
                            <label class="form-label">分配给</label>
                            <select class="form-select" name="assigned_to_id">
                                <option value="">未分配</option>
                                {% for staff in staff_members %}
                                <option value="{{ staff.id }}" {% if order.assigned_to_id == staff.id %}selected{% endif %}>
                                    {{ staff.username }} ({{ '科研人员' if staff.role == 'researcher' else '物流人员' }})
                                </option>
                                {% endfor %}
                            </select>
                        </div>
                        <div class="mb-3">
                            <label class="form-label">金额</label>
                            <input type="number" class="form-control" name="total_amount" value="{{ order.total_amount }}" step="0.01" required>
                        </div>
                        <div class="mb-3">
                            <label class="form-label">备注</label>
                            <textarea class="form-control" name="notes" rows="3">{{ order.notes }}</textarea>
                        </div>
                        <div class="d-grid gap-2">
                            <button type="submit" class="btn btn-primary">保存修改</button>
                            <a href="{{ url_for('order.order_list') }}" class="btn btn-secondary">返回</a>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %} 